import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/6 23:07
 * @description
 */
public class Solution4 {
    public static void main(String[] args) {

    }
    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {
        Map<String, Integer> map = new HashMap<>();
        int ans = 0;
        int[] cnt = new int[26];
        for (int i = 0; i < minSize; i++) {
            cnt[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < s.length() - minSize + 1; i++) {
            if (check(cnt, maxLetters)) {
                String t = s.substring(i, i + minSize);
                map.put(t, map.getOrDefault(t, 0) + 1);
                if (map.get(t) > ans) {
                    ans = map.get(t);
                }
            }
            if (i + minSize == s.length()) {
                break;
            }
            cnt[s.charAt(i) - 'a']--;
            cnt[s.charAt(i + minSize) - 'a']++;
        }
        return ans;
    }
    public boolean check(int[] cnt, int maxLetters) {
        for (int i = 0; i < 26; i++) {
            if (cnt[i] != 0) {
                maxLetters--;
                if (maxLetters < 0) {
                    return false;
                }
            }
        }
        return true;
    }
}
